Objects Reference

class vector

Definition

class vector
{
   public:
   float x,y,z,w;

   inline vector()
   { ; };

   inline vector(float x0,float y0,float z0)
   { x=x0; y=y0; z=z0; };

   inline vector(float x0,float y0,float z0,float w0)
   { x=x0; y=y0; z=z0; w=w0; };

   inline vector(vector &v)
   { *this=v; };

   inline void null(void)
   { x=y=z=0; };

   inline float length(void)
   { return (float)sqrt(x*x+y*y+z*z); };

   inline void vec(float x0,float y0,float z0)
   { x=x0; y=y0; z=z0; };

   inline void negate(void)
   { x=-x; y=-y; z=-z; };

   inline void cross(vector& v1,vector& v2)
   {
     x=v1.y*v2.z-v1.z*v2.y;
     y=v1.z*v2.x-v1.x*v2.z;
     z=v1.x*v2.y-v1.y*v2.x;
   }

   inline void normalize(void)
   {
     float len=(float)sqrt(x*x+y*y+z*z);
     if (len==0.0f) return; x/=len; y/=len; z/=len;
   }

   inline float& operator[](int i)
   { return (&x)[i]; };
};

Data Members

Member Type Description
x float vector co-ordinate in the X axis
y float vector co-ordinate in the Y axis
z float vector co-ordinate in the Z axis

Methods

constructors, null, length, vec, negate, cross, normalize, operator[]

Remarks

This class implements a 3D vector with four co-ordinates x, y, z and w. It is used for specifying points in 3D space, directions, velocity, force and also color (x is red, y is green, z is blue and w is alpha). The w co-ordinate is usually set to 1.0 when using the vector to represent 3D points and from 0.0 to 1.0 when using it as the color alpha value.

See Also

mat4x4